from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow, QMessageBox
from PyQt5.uic import loadUi

from controller.MainWindow import MainWindow
from util.SSHUtil import SSHUtil
from util.WinRmUtil import WinRmUtil


class LoginWindow:

    def __init__(self):
        self.mainWindow = QMainWindow()
        loadUi("ui/login.ui", self.mainWindow)
        self.mainWindow.setWindowIcon(QIcon('controller/icon.jpg'))
        self.mainWindow.submitButton.clicked.connect(lambda: self.submit())

    def show(self):
        self.mainWindow.show()

    def submit(self):
        ipEdit = self.mainWindow.ipEdit.text()
        usernameEdit = self.mainWindow.usernameEdit.text()
        passwordEdit = self.mainWindow.passwordEdit.text()
        try:
            # WinRmUtil(ipEdit, usernameEdit, passwordEdit)
            SSHUtil(ipEdit, usernameEdit, passwordEdit)
            mainWindow = MainWindow()
            self.mainWindow.close()
            mainWindow.show()
        except:
            QMessageBox.critical(self.mainWindow, '错误提示', "连接失败")
